<?php


namespace App\server\SMS;

use App\server\SMS\SMS;
use REST;

/**
 * Undocumented class
 *  环信
 */
class SMSServiceB implements SMS {
    public function send($phone) {
           //主帐号
    $accountSid = '2c948876870df82e01871192fce900aa';
    //主帐号Token
    $accountToken = 'b04519efa3f24494a2a72daff956dbf5';
    //应用Id
    $appId = '2c94811c87983b6b01879cada8b8005e';
    //请求地址，格式如下，不需要写https://
    $serverIP = 'app.cloopen.com';
    //请求端口
    $serverPort = '8883';
    //REST版本号
    $softVersion = '2013-12-26';
    // 初始化REST SDK
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setAccount($accountSid, $accountToken);
    $rest->setAppId($appId);

    // 发送模板短信
    $code=mt_rand(1111,4444);
    echo "Sending TemplateSMS to $phone <br/>";
    $result = $rest->sendTemplateSMS($phone, $code,1);
    if ($result == NULL) {
        echo "result error!";

    }
    if ($result->statusCode != 0) {
        echo "error code :" . $result->statusCode . "<br>";
        echo "error msg :" . $result->statusMsg . "<br>";
        //TODO 添加错误处理逻辑
    } else {
        echo "Sendind TemplateSMS success!<br/>";
        // 获取返回信息
        $smsmessage = $result->TemplateSMS;
        echo "dateCreated:" . $smsmessage->dateCreated . "<br/>";
        echo "smsMessageSid:" . $smsmessage->smsMessageSid . "<br/>";
        //TODO 添加成功处理逻辑
    }
}

//Demo调用,参数填入正确后，放开注释可以调用
//sendTemplateSMS("手机号码","内容数据","模板Id");
    }



